<?php

/**
 * 全局方法
 */
function Logs($msg)
{
  $filename = dirname(__DIR__).'/public/log.txt';
  file_put_contents($filename, '[' . date('Y-m-d H:i:s') . ']' . $msg . PHP_EOL, FILE_APPEND);
}
/**
 * 返回json数据格式
 */
function Json($data = [], $msg = 'success', $code = 200)
{
  $data = [
    'code' => $code,
    "msg" => $msg,
    "data" => $data,
  ];
  return json_encode($data, JSON_UNESCAPED_UNICODE);
}
/**
 * 获取配置文件信息
 * $configInfo 为xx.xx字符串
 */

function Config($configInfo)
{
  $configInfo = explode('.', $configInfo);
  if (count($configInfo) >= 2) {
    $filepath = '../config/' . $configInfo[0] . '.php';
    if (file_exists($filepath)) {
      $configArray = require_once($filepath);
      return $configArray[$configInfo[1]] ;
    }
  }
  return [];
}
